//
//  DiscoveryHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/6/28.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "DiscoveryHeaderView.h"

@interface DiscoveryHeaderView ()<SDCycleScrollViewDelegate>
/**
 title
 */
@property (nonatomic , strong) UILabel *titleLab;
/**
 标题下提示内容
 */
@property (nonatomic , strong) UILabel *tipsLab;

/**
 宽灰线
 */
@property (nonatomic , strong) UIView *line1;
/**
 细灰线
 */
@property (nonatomic , strong) UIView *line2;
/**
 附近的豚友title
 */
@property (nonatomic , strong) UILabel *nearbyTitle;

@end
@implementation DiscoveryHeaderView

#pragma mark - init method
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initView];
        [self initLayout];
    }
    return self;
}

- (void)initView {
    // 添加子控件
    [self addSubview:self.titleLab];
    [self addSubview:self.tipsLab];
    [self addSubview:self.cycleView];
    [self addSubview:self.chatBtn];
    [self addSubview:self.feedingLifeBtn];
    [self addSubview:self.serviceMapBtn];
    [self addSubview:self.line1];
    [self addSubview:self.nearbyTitle];
    [self addSubview:self.allBtn];
    [self addSubview:self.manBtn];
    [self addSubview:self.womanBtn];
    [self addSubview:self.line2];
}

- (void)initLayout {
    
    // 布局子控件
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(10);
        make.left.mas_equalTo(15);
        make.height.mas_equalTo(33);
    }];
    [self.tipsLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.titleLab.mas_bottom).offset(5);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(17);
    }];
    [self.cycleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.tipsLab.mas_bottom).offset(15);
        make.right.mas_equalTo(-15);
        make.height.mas_equalTo(ScaleHeight(200));
    }];
    [self.feedingLifeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.top.mas_equalTo(self.cycleView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    
    [self.chatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.cycleView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(100, 100));
        make.right.mas_equalTo(self.feedingLifeBtn.mas_left).offset(-18);
    }];
    [self.serviceMapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.feedingLifeBtn.mas_right).offset(18);
        make.top.mas_equalTo(self.cycleView.mas_bottom).offset(20);
        make.size.mas_equalTo(CGSizeMake(100, 100));
    }];
    [self.line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.chatBtn.mas_bottom).offset(30);
        make.height.mas_equalTo(10);
    }];
    [self.nearbyTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.line1.mas_bottom).offset(15);
        make.height.mas_equalTo(22);
    }];
    [self.allBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.top.mas_equalTo(self.nearbyTitle.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(56, 23));
    }];
    [self.manBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.allBtn.mas_right).offset(34);
        make.top.mas_equalTo(self.nearbyTitle.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(56, 23));
    }];
    [self.womanBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.manBtn.mas_right).offset(34);
        make.top.mas_equalTo(self.nearbyTitle.mas_bottom).offset(15);
        make.size.mas_equalTo(CGSizeMake(56, 23));
    }];
    [self.line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(self.allBtn.mas_bottom).offset(15);
        make.height.mas_equalTo(1);
    }];
}

#pragma mark - getter and setter
- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] init];
        _titleLab.textColor = [UIColor colorWithHexString:@"#363636"];
        _titleLab.font = [UIFont boldSystemFontOfSize:24];
        _titleLab.text = @"发现";
    }
    return _titleLab;
}
- (UILabel *)tipsLab {
    if (!_tipsLab) {
        _tipsLab = [[UILabel alloc] init];
        _tipsLab.textColor = [UIColor colorWithHexString:@"#999999"];
        _tipsLab.font = [UIFont systemFontOfSize:12];
        _tipsLab.text = @"待优化修改内容";
    }
    return _tipsLab;
}
- (SDCycleScrollView *)cycleView {
    if (!_cycleView) {
        _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleView.currentPageDotColor = [UIColor primaryColor];
        _cycleView.autoScrollTimeInterval = 2.0;

    }
    return _cycleView;
}
- (HButtonView *)chatBtn {
    if (!_chatBtn) {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"discover_chat"]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"我想聊聊";
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.textColor = [UIColor colorWithHexString:@"#232329"];
        _chatBtn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
    }
    return _chatBtn;
}
- (HButtonView *)feedingLifeBtn {
    if (!_feedingLifeBtn) {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"discover_life"]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"清饲生活";
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.textColor = [UIColor colorWithHexString:@"#232329"];
        _feedingLifeBtn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
    }
    return _feedingLifeBtn;
}
- (HButtonView *)serviceMapBtn {
    if (!_serviceMapBtn) {
        UIImageView *iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"discover_map"]];
        UILabel *titleLabel = [[UILabel alloc] init];
        titleLabel.text = @"服务地图";
        titleLabel.font = [UIFont systemFontOfSize:14];
        titleLabel.textColor = [UIColor colorWithHexString:@"#232329"];
        _serviceMapBtn = [[HButtonView alloc] initWithTopIcon:iconView title:titleLabel];
    }
    return _serviceMapBtn;
}
- (UIView *)line1 {
    if (!_line1) {
        _line1 = [[UIView alloc] init];
        _line1.backgroundColor = [UIColor globalBackgroundColor];
    }
    return _line1;
}
- (UILabel *)nearbyTitle {
    if (!_nearbyTitle) {
        _nearbyTitle = [[UILabel alloc] init];
        _nearbyTitle.textColor = [UIColor colorWithHexString:@"#333333"];
        _nearbyTitle.font = [UIFont boldSystemFontOfSize:16];
        _nearbyTitle.text = @"附近的豚友";
    }
    return _nearbyTitle;
}
- (UIButton *)allBtn {
    if (!_allBtn) {
        _allBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _allBtn.backgroundColor = [UIColor globalBackgroundColor];
        _allBtn.selected = YES;
        _allBtn.layer.cornerRadius = 12;
        _allBtn.layer.masksToBounds = YES;
        [_allBtn setTitle:@"全部" forState:UIControlStateNormal];
        [_allBtn setTitleColor:[UIColor colorWithHexString:@"#A3A3A3"] forState:UIControlStateNormal];
        [_allBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateSelected];
        _allBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _allBtn;
}
- (UIButton *)manBtn{
    if (!_manBtn) {
        _manBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _manBtn.backgroundColor = [UIColor globalBackgroundColor];
        _manBtn.layer.cornerRadius = 12;
        _manBtn.layer.masksToBounds = YES;
        [_manBtn setTitle:@"男" forState:UIControlStateNormal];
        [_manBtn setTitleColor:[UIColor colorWithHexString:@"#A3A3A3"] forState:UIControlStateNormal];
        [_manBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateSelected];
        _manBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _manBtn;
}
- (UIButton *)womanBtn {
    if (!_womanBtn) {
        _womanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _womanBtn.backgroundColor = [UIColor globalBackgroundColor];
        _womanBtn.layer.cornerRadius = 12;
        _womanBtn.layer.masksToBounds = YES;
        [_womanBtn setTitle:@"女" forState:UIControlStateNormal];
        [_womanBtn setTitleColor:[UIColor colorWithHexString:@"#A3A3A3"] forState:UIControlStateNormal];
        [_womanBtn setTitleColor:[UIColor primaryColor] forState:UIControlStateSelected];
        _womanBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    }
    return _womanBtn;
}
- (UIView *)line2 {
    if (!_line2) {
        _line2 = [[UIView alloc] init];
        _line2.backgroundColor = [UIColor globalBackgroundColor];
    }
    return _line2;
}
@end
